package com.zjht.gmcc.servlet.provider;

import java.io.File;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;

import com.zjht.gmcc.bean.BaseServlet;

import com.zjht.gmcc.bean.util.MyJDBC;
import com.zjht.gmcc.bean.util.MyPath;

public class RepairProvider extends BaseServlet {

	private static final long serialVersionUID = 2205937410942000119L;

	public boolean process(HttpServletRequest request, HttpServletResponse response, HttpSession session, PrintWriter out, MyJDBC myJDBC, String menu)
			throws Exception {
		int i_flag = 0;
		PreparedStatement ps;
		
		String s_msg="";
		String provid=request.getParameter("pid");
		String rangtype=request.getParameter("rangtype");
		String reason=request.getParameter("reason");
		String premit=request.getParameter("premit");
		String prereason=request.getParameter("prereason");
		String sql="update provider set RANGETYPE=?";  
		if(!premit.equals("-1")){
			if(premit.equals("1"))
			{sql+=",orderstatus=1 ";
			}else if(premit.equals("0")){
			sql+=",PERMITSTATUS=? ";
			}
			}
			sql+="where  providerid=?";
		
		
		int index=1;
		ps=myJDBC.prepareStatement(sql);
		ps.setString(index, rangtype);
		index++;
		if(!premit.equals("-1")){
			if(premit.equals("1"))
			{
			}else if(premit.equals("0")){
				ps.setString(index, premit);
				index++;
			}
			
			//sql+=",PERMITSTATUS=? ";
			
		}
		ps.setString(index, provid);
		
		i_flag=ps.executeUpdate();
		if(i_flag==1){
			sql="insert into PROVIDERlog (providerid,status,reason) values (?,?,?)";
			ps=myJDBC.prepareStatement(sql);
			ps.setString(1, provid);
			ps.setString(2, rangtype);
			ps.setString(3, reason);
			i_flag=ps.executeUpdate();
			
		}
		if(i_flag==1&&!premit.equals("-1")){
			sql="insert into PROVIDERlog (providerid,status,reason) values (?,?,?)";
			ps=myJDBC.prepareStatement(sql);
			ps.setString(1, provid);
			ps.setString(2, rangtype);
			ps.setString(3, reason);
			i_flag=ps.executeUpdate();
			
		}
			if (i_flag == 1) {
				//alert(out, "供应商信息维护成功!","provideADM.jsp");
				alertAndReturnValue(out, "供应商信息维护成功!", "1");
			} else {
				errAlert(request, out, menu, "供应商信息维护失败!");
			}
			return i_flag == 1;
		

	}

}
